/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.cmp.player.controls;

import static com.cmp.core.constants.UIDConstants.*;
import com.jme3.renderer.RenderManager;
import com.jme3.renderer.ViewPort;
import com.jme3.scene.Spatial;
import com.jme3.scene.control.AbstractControl;
import com.jme3.scene.control.Control;

/**
 * Keeps track of the scores for each team.
 * @author krummer
 */
public class ScoreControl extends AbstractControl {
    
     @Override
    public void setSpatial(Spatial spatial) {
        super.setSpatial(spatial);
        
        spatial.setUserData(SCORE_VALUE_UID, new Integer(0));
    }

    @Override
    protected void controlUpdate(float tpf) {
    }

    @Override
    protected void controlRender(RenderManager rm, ViewPort vp) {
    }
    
    public void score(){
        Integer oldScore = super.getSpatial().getUserData(SCORE_VALUE_UID);
        Integer newScore = oldScore + 1;
        this.getSpatial().setUserData(SCORE_VALUE_UID, newScore);
        
        //tell parent that there has been a score for update purposes.
        super.getSpatial().getParent().setUserData(SCORE_CHANGE_UID, Boolean.TRUE);
    }
    
    public int getScore() {
        return super.getSpatial().getUserData(SCORE_VALUE_UID);
    }

    public Control cloneForSpatial(Spatial spatial) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
    
}
